<?php 
/* P3(c)

******************************************************************************
                                                                                      
                         __                                                        
                        /__)                                                       
                       /__        P3 - moving Technologie            
                        __)                                                          
                        __)                                                          
                                                                                        
                                                                                        
       Copyright 2009 by p3.co.at                                                                                 
                                                                                        
       visit www.p3.co.at to get more Informations 
       about Teriko - Betriebsdatenerfassung                                                                                 
       - it's not allowed to change this scripts
       - it's not allowed to remove this copyright-tag

       -- you can download the complete license   
          under http://www.teriko.org

 (c) by Patrik Pfaffenbauer and P3 (http://www.p3.co.at)

 | Programname: P3.Teriko
 | Authtor: P3.Verein
 | Coder: Patrik Pfaffenbauer
 | Version: 0.1

 | Change Index
 |_____________________________________________
 |                                             |
 |4.3.2010 Erstellung | Patrik Pfaffenbauer    |
 |_____________________________________________|

******************************************************************************

P3(c) */


function GetPermission($moduleid)
{
	include("./_tables.php");
	
	session_start();
	

	$query = "SELECT * FROM ".$viewpermission." WHERE moduleid=".$moduleid." AND userid=".$_SESSION['userid'];
	$res = $GLOBALS['db']->Query($query);
	
	$biggestRights = 0;
	$biggestLine = 0;
	$count = 0;
	
	while($line = $GLOBALS['db']->Fetch($res))
	{
		$rights = $line->readPermission + $line->editPermission + $line->deletePermission + $line->specialPermission;

		if($rights > $biggestRights)
		{
			$biggestRights = $rights;
			$biggestLine = $count;
		}
		
		$count++;
	}
	
	$res = $GLOBALS['db']->Query($query);
	$count = 0;
	
	while($line = $GLOBALS['db']->Fetch($res))
	{
		if($count == $biggestLine)
		{
			return $line;
		}
		else
			continue;
		
		$count++;
	}
	
}
function PermissionCount($perm)
{
	return $perm->readPermission + $perm->editPermission + $perm->deletePermission + $perm->specialPermission;
}

function AddUserToGroup($userid, $groupid)
{
	include("./_tables.php");
	$query = "INSERT INTO ".$tbluser2group." (userid, groupid) VALUES ('".$userid."', '".$groupid."')";
	$GLOBALS['db']->Query($query);
}
function RemoveUserFromGroup($userid, $groupid)
{
	include("./_tables.php");
	$query = "DELETE FROM ".$tbluser2group." WHERE userid='".$userid."' AND groupid = '".$groupid."'";
	$GLOBALS['db']->Query($query);
}
?>